package com.nd.qa.shareplate.dom4j;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.xml.sax.InputSource;
public class DOM4JParserDemo {

	public static void main(String[] args) throws IOException {
		
		try {
			File inputFile = new File("E:\\baiduyun\\enumAppData.xml");
			//FileInputStream in = new FileInputStream(inputFile);
			//Reader reader = new InputStreamReader(in,"gb2312");
			SAXReader saxReader = new SAXReader();
			//InputStream ifile = new FileInputStream(inputFile); 
			//InputStreamReader ir = new InputStreamReader(ifile, "UTF-8"); 
			InputSource is = new InputSource(new StringReader(""));
			Document document = saxReader.read(is);
			 document.setXMLEncoding("UTF-8");
			System.out.println("Root element :" 
		            + document.getRootElement().getName());
			Element classElement = document.getRootElement();
			String modelName = classElement.attributeValue("name");
			String version = classElement.attributeValue("version");
			Element pageElement = classElement.element("page");
			System.out.println(pageElement.attributeValue("name"));
			String pageName = pageElement.attributeValue("name");
			String pageDepth = pageElement.attributeValue("depth");
			List<Element> elementLists = pageElement.elements("element");
			for (Element element : elementLists) {
				String elementType = element.attributeValue("elementType");
	            String text = element.attributeValue("text");
	            String id = element.attributeValue("id");
	            String matchid = element.attributeValue("match");
	            String actionType = element.attributeValue("click");
	            System.out.println(elementType);
	            List<Element> childElements = element.elements("");
	            if (childElements.size()!=0) {
					//从新的page开始
				}
			}
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
